<em>import React from 'react'</em>
<em>import <b>ReactDOM</b> from 'react-dom'</em>

<em>export default class <u>AddLast</u> extends React.Component</em>{
	<q>constructor</q>(<em>props</em>){
		<em>super(props)</em>
		<i>this.el</i> = <b>document.createElement</b>(<u>this.props.tag||'div'</u>) 		<em>// 创建一个 dom</em>
	}
	<em># 获取指定 dom</em>
	<s>getNode</s> = ( ) => {
		<em>const</em> { <u>el</u> } = <u>this.props</u>
		<em>const</em> <u>node</u> = <em>document.querySelector</em>( <u>el</u> )
		<em>return </em> <u>node</u> ? <u>node</u> : <b>document.body</b>
	}
	<em># 挂载时执行</em>
	<q>componentDidMount</q>( ){
		<em>this.el.setAttribute('name', this.props.name)</em>
		<s>this.getNode( )</s>.<b>appendChild</b>(<i>this.el</i>)
	}
	<em># 将要销毁时执行</em>
	<q>componentWillUnmount</q>( ){
		<s>this.getNode( )</s>.<b>removeChild</b>(<i>this.el</i>)
	}
	<q>render</q>( ){
		<em>return</em> <b>ReactDOM.createPortal</b>(
			<u>this.props.children</u>,
			<i>this.el</i>
		)
	}
}
<em># 使用</em>
<em>&lt;<u>AddLast</u> <s>name</s>='style' <s>tag</s>='style' <s>el</s>='head'&gt;</em>
	<em>&lt;div&gt;&lt;div&gt;</em>
<em>&lt;/<u>AddLast</u>&gt;</em>